package com.dmgis.hndz.service.impl;

import com.dmgis.hndz.mapper.Qxda02aMapper;
import com.dmgis.hndz.pojo.Qxda02a;
import com.dmgis.hndz.pojoVo.Qxda02aVo;
import com.dmgis.hndz.service.Qxda02aService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import static com.dmgis.hndz.common.utils.StringUtil.reStringforDate;

/**
 * @className Qxda02aServiceImpl
 * @Description TODO
 * @Author lhfy
 * @Version 1.0
 */
@Service
public class Qxda02aServiceImpl implements Qxda02aService {

    @Autowired
    private Qxda02aMapper qxda02aMapper;

    @Override
    public List<Qxda02a> getQxda02aInfo() {
        try {
            return qxda02aMapper.getQxda02aInfo();
        } catch (Exception e) {
            throw e;
        }
    }

    @Override
    public int updateQxda02aInfo(List<Qxda02aVo> qxda02aVoList) throws ParseException {
        try {
            int affectNum = 0;
            for (Qxda02aVo qxda02aVo : qxda02aVoList) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Qxda02a qxda02a = new Qxda02a();
                // 解析时间字符串
                Date date = sdf.parse(qxda02aVo.getCjTime());

                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                // 获取年月日时分秒
                qxda02a.setQxda02a030(reStringforDate(String.valueOf(calendar.get(Calendar.YEAR))));
                qxda02a.setQxda02a040(reStringforDate(String.valueOf(calendar.get(Calendar.MONTH) + 1)));
                qxda02a.setQxda02a050(reStringforDate(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))));
                qxda02a.setQxda02a060(reStringforDate(String.valueOf(calendar.get(Calendar.HOUR_OF_DAY))));
                qxda02a.setQxda02a070(reStringforDate(String.valueOf(calendar.get(Calendar.MINUTE))));
                qxda02a.setQxda02a080(reStringforDate(String.valueOf(calendar.get(Calendar.SECOND))));
                qxda02a.setQxda02a020(qxda02aVo.getSjType());
                qxda02a.setQxda02a090(qxda02aVo.getIsOpen() ? "1" : "0");

                affectNum += qxda02aMapper.updateQxda02aInfo(qxda02a);
            }
            return affectNum;
        } catch (Exception e) {
            throw e;
        }

    }
}
